﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace YJTShiftManagement
{
    public partial class InputDialog : UIForm
    {
        private const int MaxLength = 100;
        // 公共属性用于获取输入结果
        public string InputText { get; private set; }
        public bool IsConfirmed { get; private set; }

        public InputDialog(string title = "输入", string prompt = "请输入内容：")
        {
            InitializeComponent();
            this.Text = title;
            lblPrompt.Text = prompt;
        }
        private void txtInput_TextChanged(object sender, EventArgs e)
        {
            UpdateCounter();
        }
        private void UpdateCounter()
        {
            lblCounter.Text = $"{txtInput.Text.Length}/{MaxLength}";
        }

        private void btnSave_Click_1(object sender, EventArgs e)
        {
            InputText = txtInput.Text;
            if (!string.IsNullOrEmpty(InputText))
            {
                IsConfirmed = true;
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                this.ShowErrorDialog("内容不能为空！");
                return;
            }
        }

        private void btnCancel_Click_1(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void lblCounter_TextChanged(object sender, EventArgs e)
        {
            lblCounter.Text = $"{txtInput.Text.Length}/{MaxLength}";
        }

        private void txtInput_TextChanged_1(object sender, EventArgs e)
        {
            lblCounter.Text = $"{txtInput.Text.Length}/{MaxLength}";
        }
    }
}
